<template>
    <div class="slider-navs">
        <div class="logo">
            <transition name="logo-fade">
                <span
                  v-if="!isCollapse"
                  class="logo-text"
                  key="logo-text"
                >隧道管理</span>
            </transition>
            <transition name="logo-icon">
                <el-icon v-if="isCollapse" :size="30" key="logo-icon"><OfficeBuilding /></el-icon>
            </transition>
        </div>
        <el-menu    
        class="el-menu-vertical-demo"
        :class="{ 'is-collapse': isCollapse }"
        background-color="#304156"
        active-text-color="#ffd04d"
        text-color="#fff"
        :default-active="route.path"
        @open="handleOpen"
        @close="handleClose"
        router
    >
        <template v-for="item in menus" :key="item.path">
            <el-sub-menu v-if="item.children" :index="item.path">
                <template #title>
                    <el-icon><component :is="getIcon(item.icon)" /></el-icon>
                    <span class="menu-text" :class="{ 'hide': isCollapse }">{{ item.name }}</span>
                </template>
                <el-menu-item
                    v-for="child in item.children"
                    :key="child.path"
                    :index="child.path"
                >
                    <span class="menu-text" :class="{ 'hide': isCollapse }">{{ child.name }}</span>
                </el-menu-item>
            </el-sub-menu>
            <el-menu-item v-else :index="item.path">
                <el-icon><component :is="getIcon(item.icon)" /></el-icon>
                <span class="menu-text" :class="{ 'hide': isCollapse }">{{ item.name }}</span>
            </el-menu-item>
        </template>
    </el-menu>
    </div>
</template>
<script setup>
import { storeToRefs } from 'pinia'
import { useMenuStore } from '@/stores/menuStore'
import * as Icons from '@element-plus/icons-vue'
import { ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { Document, Memo, Finished, DataLine } from '@element-plus/icons-vue'

const props = defineProps({
  isCollapse: {
    type: Boolean,
    default: false
  }
})

const menuStore = useMenuStore()
const { menus } = storeToRefs(menuStore)

const route = useRoute()
const router = useRouter()

const getIcon = (iconName) => {
  return Icons[iconName] || Icons.Menu
}
</script>
<style scoped>
.el-menu-vertical-demo {
  width: 200px;
  min-height: 400px;
  transition: width 0.4s cubic-bezier(0.4,0,0.2,1);
}
.el-menu-vertical-demo.is-collapse {
  width: 64px;
}

.slider-navs{
    height: 100%;
}

.logo{
    display: flex;
    align-items: center;
    justify-content: center;
    height: 60px;
    background-color: #364e6d;
    color: #fff;
    white-space: nowrap;
}

.logo-text {
    font-size: 25px;
    display: inline-block;
    transition: opacity 0.4s cubic-bezier(0.4,0,0.2,1), font-size 0.4s cubic-bezier(0.4,0,0.2,1);
    opacity: 1;
}

.logo-fade-leave-active {
    transition: opacity 0.4s cubic-bezier(0.4,0,0.2,1), font-size 0.4s cubic-bezier(0.4,0,0.2,1);
}
.logo-fade-leave-to {
    opacity: 0;
    font-size: 0;
}

.logo-fade-enter-active {
    transition: opacity 0.4s cubic-bezier(0.4,0,0.2,1), font-size 0.4s cubic-bezier(0.4,0,0.2,1);
}
.logo-fade-enter-from {
    opacity: 0;
    font-size: 0;
}
.logo-fade-enter-to {
    opacity: 1;
    font-size: 25px;
}

/* icon动画可选 */
.logo-icon-enter-active, .logo-icon-leave-active {
    transition: opacity 0.4s cubic-bezier(0.4,0,0.2,1), transform 0.4s cubic-bezier(0.4,0,0.2,1);
}
.logo-icon-enter-from, .logo-icon-leave-to {
    opacity: 0;
    transform: scale(0.5);
}
.logo-icon-enter-to, .logo-icon-leave-from {
    opacity: 1;
    transform: scale(1);
}

.menu-text {
  display: inline-block;
  margin-left: 8px;
  font-size: 16px;
  opacity: 1;
  transition: opacity 0.4s cubic-bezier(0.4,0,0.2,1), font-size 0.4s cubic-bezier(0.4,0,0.2,1);
}
.menu-text.hide {
  opacity: 0;
  font-size: 0;
  width: 0;
  overflow: hidden;
}
</style>